﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.Engine.Control;
using Project.Module.Model;
using Project.Module.Model.CMS;
using Project.Module.DAO.BL;
using Project.Module.DAO.CMSBL;
using Project.Engine.Utilities;

namespace Project.Module.View.CMS
{
    public class CMSQuanLyComment : BasePageRazor
    {
        #region
        public string displayAdmin = string.Empty;
        public List<FeedBackModel> listComment = null;
        public List<FeedBackModel> listTopComment = null;

        private FeedBackBL feedbackBL = new FeedBackBL();
        private ProductBL productBl = new ProductBL();
        private int limit = 10;
        #endregion

        protected override void InitializePage()
        {
            base.InitializePage();
            if (Session["username_ad"] != null && ((string)(Session["username_ad"])).Length > 0)
            {
                displayAdmin = (string)(Session["username_ad"]);
                GetAllComment();
                GetTopComment(limit);
            }
        }

        private void GetAllComment()
        {
            listComment = feedbackBL.GetAllComment();

            if (listComment != null) {
                foreach (var item in listComment) {
                    if (item.EventId != 0 && item.ProductId == 0) {
                        int cateId = productBl.GetCateIdByProductId(item.EventId);
                        item.CateName = ConvertUtil.GetCateNameByCateId(cateId);
                    }
                    if (item.ProductId != 0 && item.EventId == 0)
                    {
                        int cateId = productBl.GetCateIdByProductId(item.ProductId);
                        item.CateName = ConvertUtil.GetCateNameByCateId(cateId);
                    }

                    item.ProductName = productBl.GetProductNameByProductId(item.ProductId);
                }
            }
        }

        private void GetTopComment(int _limit) {
            listTopComment = feedbackBL.GetTopComment(_limit);

            if (listTopComment != null)
            {
                foreach (var item in listTopComment)
                {
                    if (item.ProductId != 0)
                    {
                        int cateId = productBl.GetCateIdByProductId(item.ProductId);
                        item.CateName = ConvertUtil.GetCateNameByCateId(cateId);
                    }

                    item.ProductName = productBl.GetProductNameByProductId(item.ProductId);
                }
            }
        }
    }
}
